package ru.alt22.visor.php.ui.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;

import ru.alt22.visor.php.ui.providers.TestsTreeContentProvider;
import ru.alt22.visor.php.ui.providers.TestsTreeLabelProvider;
import ru.alt22.visor.php.ui.views.UnitTestsView;

public class PHPTestsViewer extends ContainerCheckedTreeViewer {

	private UnitTestsView view;

	public PHPTestsViewer(Composite parent, UnitTestsView view) {
		super(parent, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
		
		this.view = view;
		
		initialize();
	}

	public void reloadAll() {
		setInput("null");
	}

	private void initialize() {
		getControl().setLayoutData(new GridData(GridData.FILL_BOTH));

		TreeColumn columnName = new TreeColumn(getTree(), SWT.CHECK | SWT.LEFT);
		columnName.setWidth(300);

		TreeColumn columnResult = new TreeColumn(getTree(), SWT.CENTER);
		columnResult.setWidth(80);

		setContentProvider(new TestsTreeContentProvider());
		setLabelProvider(new TestsTreeLabelProvider());
		getTree().addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				view.showTestDetails();
			}
		});
		getTree().addMouseListener(new MouseAdapter() {
			public void mouseDoubleClick(MouseEvent e) {
				view.runSelectedTest();
			}
		});
		reloadAll();
	}

}